#!/usr/bin/perl -w

use strict;
use Getopt::Long;

my ($prog,$progdir);
BEGIN {
    $0 =~ m{(.*)/(.*?)};
    ($progdir,$prog) = ($1,$2);
    $progdir = '.' unless $progdir;
    #print "$progdir\n";
    push @INC, "$progdir/lib", "$progdir";
    #print join(':',@INC),"\n";
}

$main::verbose = 1;

my $opts = {v=>1,q=>0};

if(! GetOptions($opts,'v+','q+')) { die usage(); }

$main::verbose = $opts->{v};
$main::verbose -= $opts->{q};

print "Setting verbosity (debugging) level to '$opts->{v}'.\n" if $opts->{v} > 1;

die usage() unless @ARGV;

sub usage {
    ("Usage: $0 [-v [-v ...]] session_id [session_id] ...\n".
     " -v   increase verbosity.\n".
     " -q   decrease verbosity.\n"
    );
}

use XNAT::Connection;

print "$prog: Creating Connection:\n" if $main::verbose > 1;
my $xconn = XNAT::Connection->new(host=>'gspcentral');
print "$prog: OK\n" if $main::verbose > 1;


my $errors = 0;

foreach my $session_id (@ARGV) {
    $xconn->getFCScans({id=>$session_id}) || $errors ++;
}

if($errors) {
    print "ERROR: Something went wrong. Exiting non-zero.\n";
    exit 1;
}

exit;
__END__
